<?php

namespace falcon5\inc\WPProviders;

use falcon5\inc\Base\Common;
use falcon5\inc\Base\ServiceProviderInterface;
use hollisho\helpers\ArrayHelper;

class LanguageSwitcherMenuItems implements ServiceProviderInterface
{
    private $options = [];

    public function register()
    {
        $settings = get_option(Common::PLUGIN_ID, []);
        $this->options = $settings;
        if (ArrayHelper::getValue($this->options, 'showInMenu')) {
            add_filter('wp_nav_menu_items', [$this, 'register_menu_item'], 10, 2);
        }
    }

    public function register_menu_item($items, $args)
    {
        if($args->theme_location == $this->options['showInMenu']) {
            // 只生成基础的菜单项容器
            $html = '<li class="menu-item menu-item-falcon5" data-falcon5-menu-switcher></li>';
            $items .= $html;
        }
        return $items;
    }
}